<?php
if (!defined('IN_XLP')) {
        exit('Access Denied');
}
$Document = array(
  'pageid' => 'guess-add', //页面标示
  'pagename' => '添加题目', //当前页面名称
  'mycss' => array('guess/select2'), //加载的css样式表
  'myjs' => array('guess/select2.min'), //加载的js脚本
  'footerjs' => array(''),
  'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public'); ?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public'); ?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
        <section class="main padder">
                <div class="clearfix">
                        <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'], '_'); ?></h4>
                </div>
                <div class="row">

                        <div class="col-sm-12">
                                <div class="panel">
                                        <div class="clearfix panel-body">
                                                <div class="alert alert-warning alert-block">
                                                        <button data-dismiss="alert" class="close" type="button"><i class="fa fa-times"></i></button> 
                                                        <h4><i class="fa fa-bell-o"></i>注意事项：</h4> 
                                                        <p><span class="red">正确答案即为答案前面的A，B，C，D...（不区分大小写）</span> </p>
                                                        <p><span class="red">选项依次添加顺序要按照A，B，C，D...来</span> </p>
                                                        <p><span class="red">选项格式：A、选项格式  B、选项格式 C、选项格式 D、选项格式，选项中不要出现英文逗号</span> </p>
                                                        <p> 1、备选答案个数不限，以1-4个为宜 </p>
                                                        <p> 2、图片最佳尺寸300px*200px </p>
                                                        <p> 3、增加积分为：0~3时，题目困难程度为：容易；4~6时，题目困难程度为：困难</p>
                                                </div>
                                        </div>
                                </div>
                        </div>
                        <div class="col-sm-6">
                                <section class="panel">
                                        <div class="clearfix panel-body">
                                                <form class="form-horizontal" method="post" id="form1">
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">题目</label>
                                                                <div class="col-sm-8">
                                                                        <input type="text" name="title" id="title" placeholder="" class="form-control" value="" />
                                                                </div>
                                                        </div>
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">选项</label>
                                                                <div class="col-sm-5">
                                                                        <input type="hidden" id="select2-tags"  lass="form-control" name="content" style="width:250px" value="" />
                                                                       <button class="btn btn-primary" type="button" id="check" >雷同验证</button>
                                                                </div>
                                                        </div>
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">题目来源</label>
                                                                <div class="col-sm-4">
                                                                        <select name="verify" class="form-control" id="verify">
                                                                                <?php foreach ($source as $key => $val) { ?>
                                                                                        <option value="<?php echo $key; ?>" ><?php echo $val; ?></option>
                                                                                <?php } ?>
                                                                        </select>
                                                                </div>
                                                        </div>  
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">正确选项</label>
                                                                <div class="col-sm-2">
                                                                        <select name="options" class="form-control" id="options">
                                                                                <option value="A" >A</option>
                                                                                <option value="B" >B</option>
                                                                                <option value="C" >C</option>
                                                                                <option value="D" >D</option>
                                                                                <option value="E" >E</option>
                                                                                <option value="F" >F</option>
                                                                        </select>
                                                                </div>
                                                        </div>
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">答对加积分</label>
                                                                <div class="col-sm-2">
                                                                        <input type="text" name="credit_add"  placeholder="" class="form-control" value="" />
                                                                </div>
                                                        </div>
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">答错扣积分</label>
                                                                <div class="col-sm-2">
                                                                        <input type="text" name="credit_del"  placeholder="" class="form-control" value="" />
                                                                </div>
                                                        </div>
                                                        <div class="form-group">
                                                                <label class="col-sm-2 control-label">上传图片</label> 
                                                                <div class="col-sm-4"> 
                                                                        <input name="pic" id="pic"  type="text" class="form-control"  value="" />    
                                                                        <iframe width="280" height="24" src='<?php echo U('upload/index', array('path' => 'guess', 'id' => 'pic', 'ids' => 'setfileList')); ?>' scrolling='No' frameborder='0'></iframe>
                                                                </div>
                                                        </div>
                                                        <div id="upload"></div>
                                                        <div class="form-group"> 
                                                                <label style="width:100px;" class="col-sm-2 control-label"></label>
                                                                <div class="col-sm-20">
                                                                        <button class="btn btn-primary" id="sub-ok" data-loading-text="正在提交..."  type="submit">保存</button>
                                                                        <button class="btn btn-white col-md-offset-1" type="button" id="reset" >取消</button>
                                                                </div> 
                                                        </div>
                                                </form>
                                        </div>
                                </section>
                        </div>
                        <div class="col-sm-6">
                                <div class="panel">
                                        <div class="clearfix panel-body">
                                                <div class="alert alert-success">
                                                        <h4><i class="fa fa-bell-o"></i>题目可能雷同列表</h4> 
                                                        <p>没有雷同信息</p>
                                                </div>
                                        </div>
                                </div>   
                        </div>
                </div>
        </section>
</section>

<!--主体 结束--> 
<script>
        function setfileList(obj) {
                //console.log(obj);
                $("#upload").append('<div class="alert alert-info"> <button data-dismiss="alert" id="close" rel="' + obj.savepath + '" class="close" type="button"><i class="fa fa-times"></i></button> \n\
           <a  href="' + obj.file_url + '" rel="pop"  target="_blank" ><img style="width:100px;height:100px;" src="' + obj.file_url + '" ></a></div>');
        }
        $(function() {
                /**        $(document).on('click','#close',function(){
                 var path=$(this).attr('rel');
                 $.post('<?php //echo U('guess/imgdelete');                   ?>', {'path':path}, function(result) {
                 if (result.status == 1) {
                 if($('#pic').val()==path){
                 $('#pic').val("");    
                 }
                 Msg.ok('已删除');
                 } else {
                 Msg.error(result.info);
                 }
                 }, 'json');
                 return false;
                 });*/
                $('#check').click(function() {
                        $('div.alert-success  p').remove();
                        var content = $('#select2-tags').val();
                        if (!content) {
                                Msg.error('选项内容不能为空');
                                return false;
                        }
                        Msg.loading();
                        $.post('<?php echo U('guess/checktitle'); ?>', {'content': content}, function(result) {
                                Msg.hide();
                                if (result.status == 1) {
                                        var data = result.data;
                                        // alert(data[0].content);
                                           if (data.length==0) {
                                                $('.alert-success').append('<p>没有雷同信息</p>');
                                                 return false;
                                        }
                                        for (var i = 0; i < data.length; i++) {
                                                $('.alert-success').append('<p><strong>' + (i + 1) + '、</strong>\n\
                                        <a href="<?php echo BASE_URL;?>content/guess/edit/id/'+data[i].id+'.html" ><span class="red" >' + data[i].title + '<span></a></p><p>' + data[i].content + '</p>');
                                        }
                                } else {
                                        Msg.error(result.info);
                                        return false;
                                }
                        }, 'json');
                        return false;
                })
                $('#reset').click(function() {
                        document.location = '<?php echo U('guess/index'); ?>';
                });
                $('#form1').submit(function() {
                        var title = $('#title').val();
                        var content = $('#select2-tags').val();
                        if (!title) {
                                Msg.error('题目不能为空');
                                return false;
                        }
                        if (!content) {
                                Msg.error('选项内容不能为空');
                                return false;
                        }
                        Msg.loading();
                        $.post('<?php echo U('guess/post'); ?>', $(this).serialize(), function(result) {
                                Msg.hide();
                                resetSubmit("#sub-ok", '保存');
                                if (result.status == 1) {
                                        Msg.ok('添加成功');
                                } else {
                                        Msg.error(result.info);
                                }
                        }, 'json');
                        return false;
                });

                $("#select2-tags").select2({
                        tags: [],
                        tokenSeparators: [",", " "]
                });
        });
</script>
<?php
include getTpl('footer', 'public');
?>